<template>
  <div class="box">
    <div class="header">
      <span class="iconfont icon-fanhui" @click='back'></span>
      <div class="title">买房</div>
    </div>
    <div class="inp">
      <span @click="show">{{cityList[cityIndex]?cityList[cityIndex]:''}} <span :class="arrow"></span>

      </span>
      <van-picker :columns="cityList" show-toolbar visible-item-count=6 v-show="showCity" class="list"
        @confirm='getData' />
      <div class="input">
        <input type="text" placeholder="请在这里输入区域/商圈">
        <span class="iconfont icon-sousuo"></span>
      </div>
      <navigator url="/pages/mapHouse/index">地图找房</navigator>

    </div>
    <div class="tab">
      <dl>
        <dt><img src="../../static/buyHouse/1.jpg" alt=""></dt>
        <dd>找商铺</dd>
      </dl>
      <dl>
        <dt><img src="../../static/buyHouse/2-03.jpg" alt=""></dt>
        <dd>找写字楼</dd>
      </dl>
      <dl>
        <dt><img src="../../static/buyHouse/2-06.jpg" alt=""></dt>
        <dd>找小区</dd>
      </dl>
    </div>
    <div class="menu">
      <navigator url='/pages/buyHouse/area'>区域<span :class="arrow"></span></navigator>
      <navigator url='/pages/buyHouse/price'>价格<span :class="arrow"></span></navigator>
      <navigator url='/pages/buyHouse/type'>户型<span :class="arrow"></span></navigator>
      <navigator url='/pages/buyHouse/filter'>筛选<span :class="arrow"></span></navigator>
      <div class="iconfont icon-qiehuan"></div>
    </div>
    <div class="houseList">
      <dl v-for='(item,index) in houseList' :key='index'>
        <!-- <div class="load" v-show=''>加载中...</div> -->
        <dt><img :src='"http://157.122.54.189:9060"+item.houseImg' alt="" mode='widthFix'>
        </dt>
        <dd>
          <h2>{{item.title}}</h2>
          <p>{{item.desc}}</p>
          <p><span>{{item.price+'元'}}</span></p>
          <p><i v-for="(ite,i) in item.tags" :key='i'>{{ite}}</i></p>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import '../../static/buyHouse/fonts/buyHouse/iconfont.css'
import { getCity, getHouse, getList2 } from '../../service/buyHouse.js'
import { mapState } from 'vuex'
export default {
  data () {
    return {

    }
  },
  computed: mapState([
    'cityList',
    'showCity',
    'cityIndex',
    'arrow',
    'houseList',
    'start',
    'end',
  ]),

  async onShow () {
    let res = await getCity()
    if (res) {
      this.$store.state.cityListAll = res.body
      this.$store.state.city = res.body[0].value
      this.$store.state.cityList = res.body.map(item => {
        return item.label
      })
    }
    if (!this.$store.state.houseList.length) {
      let result = await getHouse({
        cityId: this.$store.state.city,
        start: this.$store.state.start,
        end: this.$store.state.end,
      })
      if (result) {
        this.$store.state.houseList = result.body.list

      }
    }
    let result = await getList2(this.$store.state.city)
    // let result = await getList2('AREA|88cff55c-aaa4-e2e0')
    if (result) {
      this.$store.state.list = result
    }
  },
  onReachBottom: async function () {

    this.$store.state.end += 10
    let result = await getHouse({
      cityId: this.$store.state.city,
      start: this.$store.state.start,
      end: this.$store.state.end,
    })
    if (result) {
      this.$store.state.houseList = result.body.list

    }
  },
  methods: {
    show () {
      this.$store.state.showCity = true
      this.$store.state.arrow = 'iconfont icon-f11'
    },
    async getData (e) {
      this.$store.state.showCity = false
      this.$store.state.cityIndex = e.detail.index
      this.$store.state.city = this.$store.state.cityListAll[e.detail.index].value
      let result = await getHouse({
        cityId: this.$store.state.city,
        start: this.$store.state.start,
        end: this.$store.state.end,
      })
      if (result) {
        this.$store.state.houseList = result.body.list

      }
      this.$store.state.arrow = 'iconfont icon-f11-copy'
    },
    back () {
      wx.switchTab({ url: '/pages/index/index' })
    }
  }
  ,


}
</script>

<style lang='scss' scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.load {
  text-align: center;
  width: 100%;
  height: 60rpx;
}
html,
body {
  width: 100%;
  height: 100%;
}
.box {
  width: 100%;
  // background-color: #eee;
  .header {
    width: 100%;
    height: 200rpx;
    color: #fff;
    background: linear-gradient(90deg, #0272f0, #36a2fe);
    display: flex;
    align-items: center;
    position: relative;
    span {
      position: absolute;
      left: 40rpx;
      top: 50%;
      transform: translate(0, -50%);
    }
    .title {
      width: 100%;
      text-align: center;
    }
  }
  .inp {
    background-color: #fff;
    width: 100%;
    height: 80rpx;
    margin: 20rpx 0;
    font-size: 36rpx;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .list {
      width: 100%;
      height: 500rpx;
      position: fixed;
      bottom: 0;
      left: 0;
      background: gainsboro;
    }
    .input {
      width: 380rpx;
      height: 70rpx;
      border: solid 1px #ccc;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20rpx;
      background-color: #eee;
      input {
        font-size: 26rpx;
        padding: 10rpx 30rpx;
      }
    }
  }
  .tab {
    background-color: #fff;
    width: 100%;
    display: flex;
    justify-content: space-around;
    margin: 30rpx 0;
    dl {
      dt {
        text-align: center;
        margin-bottom: 20rpx;
        img {
          width: 70%;
          height: 100rpx;
        }
      }
    }
  }
  .menu {
    background-color: #fff;
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: solid 1px #000;
    border-bottom: solid 1px #000;
    padding: 20rpx 0;
    box-sizing: border-box;
  }
  .houseList {
    width: 100%;
    padding: 0 30rpx;
    box-sizing: border-box;
    dl {
      width: 100%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      background-color: #fff;
      margin: 60rpx 0;
      border-bottom: solid 1px #eee;
      dt {
        width: 30%;

        img {
          width: 100%;
          height: 100%;
          max-height: 200rpx;
        }
      }
      dd {
        width: 60%;
        h2 {
          font-weight: bold;
        }
        p {
          font-size: 26rpx;
          margin: 20rpx 0;
          span {
            color: orange;
            font-size: 36rpx;
          }
          i {
            display: inline;
            padding: 10rpx;
            background-color: #eee;
            margin-right: 20rpx;
          }
        }
      }
    }
  }
}
</style>